package cn.data.collection.util;

import java.util.HashMap;
import java.util.Map;

import org.jsoup.nodes.Document;

import cn.data.collection.constant.RegisterKey;

public class ProgramRegister {
	public static final Map<String,Object> REGIESTDATA = new HashMap<String,Object>();

	public void init() throws Exception {
		String url = "http://www.cnblogs.com/askuser/p/4794606.html";
		HttpClientUtils httpClientUtils = new HttpClientUtils();
		httpClientUtils.initHttpClient();
		String strContent = httpClientUtils.loadUrl(url);
		Document doc = httpClientUtils.instr2Jsoup(strContent);
		String result = doc.select("#cnblogs_post_body").toString();
		String member01 = result.substring(result.indexOf(".member01"),result.indexOf(".member02"));
		String str = member01.substring(member01.indexOf("{") + 1, member01.indexOf("}")).toString();
		String[] strArray = str.split(";");
		for (int i = 0; i < strArray.length; i++) {
			testLogic(strArray[i].trim());
		}
		
		httpClientUtils.releaseConnection();
	}
	
	private void testLogic(String data){
		String[] logic = data.split(":");
		for(int i = 0; i < logic.length; i++){
			if(logic[0].equals("height")&&logic[1].equals("16px")){
				REGIESTDATA.put(RegisterKey.PROGRAM_VALIDATE, true);//程序是否生效验证
			}else if(logic[0].equals("width")&&logic[1].equals("40px")){
				REGIESTDATA.put(RegisterKey.COLLECTION_BUT_VALIDATE, true);//采集按钮是否有效
			}else if(logic[0].equals("direction")&&logic[1].equals("test")){
				REGIESTDATA.put(RegisterKey.TEST_BAT_VALIDATE, true);//测试版本不能使用
			}
		}
	}
	
	public static void main(String[] args) throws Exception {
		new ProgramRegister().init();
		System.out.println(REGIESTDATA.entrySet().size());
	}
}
